// $Id: bool_ref.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <boost/test/unit_test.hpp>
#include <xpcom/proxy/bool_ref.hpp>

BOOST_AUTO_TEST_CASE(test_bool_ref)
{
    using namespace xpcom;
    using namespace xpcom::proxy;

    bool_ref b;
    BOOST_CHECK(!b);
    BOOST_CHECK(b.get() == false_);

    bool_ref b1(b);
    BOOST_CHECK(!b1);
    BOOST_CHECK(b1.get() == false_);

    bool_ref b2(true);
    BOOST_CHECK(b2);
    BOOST_CHECK(b2.get() == true_);

    b = true;
    BOOST_CHECK(b);
    BOOST_CHECK(b.get() == true_);

    b = false;
    BOOST_CHECK(!b);
    BOOST_CHECK(b.get() == false_);

    // assignment from bool_ref
    bool_ref b3;
    b3 = true;

    b = b3;
    BOOST_CHECK(b);
    BOOST_CHECK(b.get() == true_);

    // swap
    b1.swap(b2);
    BOOST_CHECK(!b2);
    BOOST_CHECK(b2.get() == false_);
    BOOST_CHECK(b1);
    BOOST_CHECK(b1.get() == true_);
}
